﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace SWCad
{
    public partial class IUHChart : UserControl
    {
        public IUHChart()
        {
            InitializeComponent();
        }
        public ClassLib clib = new ClassLib();

        String InFileName, OutFileName;
        String[] BatchFileNames;
        enum iInMode : int { iNo = 0, iSingle = 1, iBatch = 2 }; //0 no input; 1 single input; 2 batch input
        int iInFileMode = (int)iInMode.iNo;
        enum iMValueMode : int { iCustom = 0, iFJSea = 1, iFJLand = 2 }; //0 给定值; 1 福建沿海; 2 福建内地
        int iMValueMethod = (int)iMValueMode.iCustom;
        double dblSMCstm; //给定值
        bool bHasDrawChart = false;

        public void getInPutValue(ClassLib clib)
        {
            //    textBoxCSName.Text = clib.strBZM;
            textBoxRainSharp.Text = clib.strYX;
            textBoxArea.Text = clib.dblF.ToString();
            textBoxRiverLength.Text = clib.dblHL.ToString();
            textBoxJ.Text = clib.dblBJ.ToString();
            textBoxZB.Text = clib.iZB.ToString();
            textBoxSm.Text = clib.dblSm.ToString();
            textBoxFc.Text = clib.dblFc.ToString();
            textBoxMp.Text = clib.iMp.ToString();
            textBoxM.Text = clib.iM.ToString();

            if (checkedListBoxPL.Items.Count > 0)
            {
                checkedListBoxPL.Items.Clear();
            }
            for (int i = 0; i < clib.iMp; i++)
            {
                checkedListBoxPL.Items.Add("P=" + clib.dblPP[i] + "%");
            }
            checkedListBoxPL.SetItemChecked(0, true);
        }
        private void setInPutValue(ClassLib clib)
        {
            //    textBoxCSName.Text = clib.strBZM;
            clib.strYX = textBoxRainSharp.Text;
            clib.dblF = double.Parse(textBoxArea.Text);
            clib.dblHL = double.Parse(textBoxRiverLength.Text);
            clib.dblBJ = double.Parse(textBoxJ.Text);
            clib.iZB = int.Parse(textBoxZB.Text);
            clib.dblSm = double.Parse(textBoxSm.Text);
            clib.dblFc = double.Parse(textBoxFc.Text);
            clib.iMp = int.Parse(textBoxMp.Text);
            clib.iM = int.Parse(textBoxM.Text);

            //             if (checkedListBoxPL.Items.Count > 0)
            //             {
            //                 checkedListBoxPL.Items.Clear();
            //             }
            //             for (int i = 0; i < clib.iMp; i++)
            //             {
            //                 checkedListBoxPL.Items.Add("P=" + clib.dblPP[i] + "%");
            //             }
            //             checkedListBoxPL.SetItemChecked(0, true);
        }
        //由输入文件计算图标显示所需数据
        private void CalChart()
        {
            String ConnectFile = InFileName + "*" + OutFileName + "*";
            //获取字节个数，传递给DLL中的函数
            byte[] bit = Encoding.Default.GetBytes(ConnectFile);
            Int32 InLen = bit.Length;
            //           c.testWTSTR(unicodeString, strLength);
            clib.readTLJS(InFileName);
            clib.TLJS(ConnectFile, InLen); //计算
            clib.readTLJSouttemp(OutFileName + "temp");
            getInPutValue(clib);
        }
        //添加控制断面
        private void AddCSName()
        {
            cmbCSNames.Items.Add(clib.strBZM);
            cmbCSNames.SelectedIndex = cmbCSNames.Items.Count - 1;
        }
        //绘图
        private void DrawChart()
        {
            // Check if a demo module node is selected. Demo module is attached to the node
            // as the Tag property
            clib.TLJS2Plot();
            LineChart LineChart = new LineChart(clib);
            LineChart.Dock = DockStyle.Fill;
            LineChart.Name = "LineChart";
            if (ChartControl.Controls.Count > 0)
                ChartControl.Controls[0].Dispose(); //刷新图
            ChartControl.Controls.Add(LineChart);
            bHasDrawChart = true;
        }

        //选择绘制某个频率的成果
        private void checkedListBoxPL_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        private void ChartControl_MouseMoveEvent(System.Object eventSender, AxXtremeChartControl._DChartControlEvents_MouseMoveEvent eventArgs)
        {
            XtremeChartControl.ChartElement Element;
            Element = ChartControl.HitTest(eventArgs.x, eventArgs.y);

            XtremeChartControl.ChartSeriesPoint Point;

            Point = (XtremeChartControl.ChartSeriesPoint)Element;

            if (Point != null)
            {
                System.Diagnostics.Debug.WriteLine("Point " + Point[0]);
            }
        }

        private void Line_Resize(System.Object eventSender, System.EventArgs eventArgs)
        {
            //           menuStrip1.Width = ClientRectangle.Width - 2 * gbOptions.Left;
            //           gbOptions.Width = ClientRectangle.Width - 2 * gbOptions.Left;
            ChartControl.SetBounds(ChartControl.Left, ChartControl.Top, ClientRectangle.Width - 2 * ChartControl.Left + ChartControl.Left, ClientRectangle.Height - ChartControl.Top - 8);
        }

        //选择指定控制断面 2012-1-27
        private void cmbCSNames_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        private void updateMenu()
        {
            if ((int)iInMode.iNo == iInFileMode)
            {
                exportResultToolStripMenuItem.Enabled = false;
            }
            else if ((int)iInMode.iSingle == iInFileMode || (int)iInMode.iBatch == iInFileMode)
            {
                exportResultToolStripMenuItem.Enabled = true;
            }
            saveChartAsPNGToolStripMenuItem.Enabled = bHasDrawChart;
        }
        private void updateItem()
        {
            if (0 == double.Parse(textBoxSm.Text))
            {
                textBoxZB.Enabled = false;
                textBoxSm.Enabled = false;
                cmbSmMtd.Enabled = false;
            }
            else
            {
                textBoxZB.Enabled = true;
                textBoxSm.Enabled = true;
                cmbSmMtd.Enabled = true;
            }
        }
        //输出计算成果汇总表
        //第一行为各计算频率
        //余下为各断面相应频率下得洪峰流量

        private void btn_CalNew_Click(object sender, EventArgs e) //刷新绘图区
        {

        }
        //添加m值计算方法类型
        private void InitMValueCmb()
        {
            cmbSmMtd.Items.Clear();
            cmbSmMtd.Items.Add("给定m值");
            cmbSmMtd.Items.Add("福建沿海区");
            cmbSmMtd.Items.Add("福建内地区");
            cmbSmMtd.SelectedIndex = 0;
            clib.readTLJS(InFileName); //若不加这句，clib.dblsm变成零？？
            dblSMCstm = clib.dblSm;
            getInPutValue(clib);
        }
        private void cmbSmMtd_SelectedIndexChanged(object sender, EventArgs e) //选择m值计算方法
        {

        }

        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
    }
}
